<?php


    session_start();
	include("../includes/conn.php");

    $ucode=isset($_SESSION['ucode'])?$_SESSION['ucode']:1;	

	$now_time=time();
	$score=isset($_POST['score'])?$_POST['score']:0;
	$returnStr=array('ustatus' =>'4','umes'=>'');

	if($ucode&&$score!=0)
	{
		$data=$dbconn->fetch($dbconn->query("select * from ".DBQIAN."_score where ucode='".$ucode."'"));

		if(!$data){

			$sql = "insert into ".DBQIAN."_score (ucode,score,time) values ('$ucode','$score','$now_time')";
					
			$dbconn->noretquery($sql);
			$returnStr['ustatus']=1;
			$returnStr['umes']="你当前接的最大月饼数：".$score."个";
			echo json_encode($returnStr);
		}
		else 
		{
			if($score>intval($data['score']))
			{
				$dbconn->noretquery("update ".DBQIAN."_score set score='$score',update_time='$now_time' where ucode='".$ucode."'");
				$returnStr['ustatus']=2;
				$returnStr['umes']="你当前接的最大月饼数：".$score."个月饼";
			    	
			}
			else
			{
				$returnStr['ustatus']=3;
				$returnStr['umes']="你当前接的最大月饼数：".intval($data['score'])."个月饼";
			}

			 echo json_encode($returnStr);

		}

	}
	else
	{
        $returnStr['ustatus']=4;
        // $returnStr['umes']="";必须在微信环境下使用，否则结果不记录
		echo json_encode($returnStr);
	}

	


	
/*	
   $conn = mysql_connect("localhost","root","123456");
   $mes='error';
	if (!$conn)
	  {
	  	echo json_encode('Could not connect');exit;
	  }
	  else
	  {
            mysql_query("set names 'utf8'"); //数据库输出编码 应该与你的数据库编码保持一致.南昌网站建设公司百恒网络PHP工程师建议用UTF-8 国际标准编码.
			mysql_select_db('test',$conn); //打开数据库

            $now_time=time();
            $score=isset($_POST['score'])?$_POST['score']:0;
			$sql = "insert into wx_score (score,create_time) values ('$score','$now_time')";
			 
			mysql_query($sql);

			echo '1';
			 
			mysql_close(); //关闭MySQL连接
	 }*/

?>